﻿using AirlineBookingSystem.Payment.Core.Entities;
using AirlineBookingSystem.Payment.Core.Repositories;
using Dapper;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AirlineBookingSystem.Payment.Infrastructure.Repositories
{
    public class PaymentRepository : IPaymentRepository
    {
        private readonly DbConnection _dbConnection;

        public PaymentRepository(DbConnection dbConnection)
        {
            _dbConnection = dbConnection;
        }

        public async Task ProcessPaymentAsync(Payments payment)
        {
            const string sql = @"
            INSERT INTO Payment(Id,BookingId,Amount,PaymentDate)
            VALUES(@Id,@BookingId,@Amount,@PaymentDate)";
            await _dbConnection.ExecuteAsync(sql, payment);

        }

        public async Task RefundPaymentAsync(Guid id)
        {
            const string sql = "delete from payment where Id=@Id";
            await _dbConnection.ExecuteAsync(sql, new { Id = id });
        }
    }
}
